// Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved.
// This source file is part of the Cangjie project, licensed under Apache-2.0
// with Runtime Library Exception.
//
// See https://cangjie-lang.cn/pages/LICENSE for license information.

#include <memory>

#include "cangjie/AST/Walker.h"

#include "Migrators/FileMigrator.h"
#include "Migrators/ProjectMigrator.h"
#include "Migrators/DevecoMigrator.h"
#include "Migrators/Migrator.h"

using namespace CangjieMigrator;

Migrator::Migrator(const Option &option, std::unique_ptr<Rules::RuleList> rules)
    : version(option.version), rules(std::move(rules))
{}

std::unique_ptr<Migrator> Migrator::Create(
    Path defaultCangjieHome, Option option, std::string version, std::unique_ptr<Rules::RuleList> rules)
{
    switch (option.mode) {
        case UPDATER_MODE_FILE:
            return std::make_unique<FileMigrator>(
                std::move(defaultCangjieHome), std::move(option), std::move(version), std::move(rules));
        case UPDATER_MODE_PROJECT:
            return std::make_unique<ProjectMigrator>(
                std::move(defaultCangjieHome), std::move(option), std::move(version), std::move(rules));
        case UPDATER_MODE_DEVECO:
            return std::make_unique<DevecoMigrator>(
                std::move(defaultCangjieHome), std::move(option), std::move(version), std::move(rules));
        default:
            return nullptr;
    }
}

std::string Migrator::GetVersion() const
{
    return version;
}
